﻿using System;
using Core.Model.Types;

namespace Core.Model.Chunks
{
    public class Chunk : IDisposable
    {
        #region Constants

        public static readonly Vector3B Size = new Vector3B(16, 128, 16);

        public static readonly int BlockCount = Size.X*Size.Y*Size.Z;

        #endregion

        #region .ctor

        public Chunk(VectorIndex index)
        {
            ReinitializeBlock(index);
        }

        #endregion

        #region Properties

        public byte UpperGroundHeight = 0;

        public byte LowerGroundHeight = Size.Y;

        public int VertexCount;

        public int IndexCount;

        public int PrimitivesCount;

        [Obsolete("Заменить на Position3")]
        public Vector3F Index3;

        public VectorIndex Index;

        public VectorIndex Position;

        public Vector3F Position3;

        public PlantArray LowerPlant = new PlantArray(Size.X + 2, Size.Z + 2);

        public PlantArray UpperPlant = new PlantArray(Size.X + 2, Size.Z + 2);

        public BoundingBoxF BoundingBox;

        public bool IsGenerated;

        public bool IsReady;

        #endregion

        public void ReinitializeBlock(VectorIndex index)
        {
            Index = index;

            Index3 = new Vector3F(index.X, 0, index.Z);

            Position = new VectorIndex(index.X * Size.X, index.Z * Size.Z);

            Position3 = new Vector3F(index.X * Size.X, 0, index.Z * Size.Z);

            BoundingBox = new BoundingBoxF(new Vector3F(Position.X, 0, Position.Z),
                                          new Vector3F(Position.X + Size.X, Size.Y, Position.Z + Size.Z));

            IsReady = false;
            IsGenerated = false;
        }

        public virtual void Dispose()
        {
        }
    }
}